﻿using Microsoft.Extensions.Configuration;
using StarsAdmin.Core.Helpers;

namespace StarsAdmin.Core.App.Models
{
    public class Sql
    {
        private readonly IConfiguration _configuration;
        private string _database;
        private string _sqlConn;

        public Sql(IConfiguration configuration)
        {
            _configuration = configuration.NotNull();
            Initialize();
        }

        /// <summary>
        /// 数据库类型
        /// </summary>
        public string Database { get => _database; }

        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public string SqlConn { get => _sqlConn; }

        private void Initialize()
        {
            var connectionStrings = _configuration.GetSection("ConnectionStrings").NotNull();
            _database = connectionStrings.GetSection("Database").Value.NotNull();
            _sqlConn = connectionStrings.GetSection(Database).Value.NotNull();
        }
    }
}